package com.vint;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.util.ArrayList;

import javax.swing.ImageIcon;

public class MyRunnable implements Runnable{
	
	HeroPlane hp;
	Graphics g;
	ArrayList<Boom> booms;
	ArrayList<BasicPlane> emenies;
	ArrayList<Boom> herobooms;
	ArrayList<Explore> ex = new ArrayList<>();
	
	ScoreShow sshow;
	int score = 0;
	public void run(){
		ImageIcon imageicon = new ImageIcon(GameFrame.class.getResource("/0-1-1.jpg"));
		Image img = imageicon.getImage();
		int count = 0;
		while(true){
			
			g.drawImage(img, 0, 0, null);
			hp.draw(g);
			g.setColor(Color.RED);
			g.fillRect(10, 30, hp.HP,15);
			g.setColor(Color.BLUE);
			g.fillRect(10, 50, hp.TP, 15);
			sshow.show(score);

			count++;
			if(count%100 == 0){
				if(hp.TP<100){
					hp.TP = hp.TP+5;
				}
			}else if(count == 1001){
				count = 0;
			}
			for(int i = 0;i<emenies.size();i++){
				emenies.get(i).move();
				emenies.get(i).draw(g);
				if(emenies.get(i).isout()){
					emenies.remove(i);
				}
				
			}
			for(int i = 0;i<booms.size();i++){
				booms.get(i).move();
				booms.get(i).draw(g);
				if (booms.get(i).hithero(hp)) {
					hp.HP = hp.HP-5;
					if(hp.HP<=0){
						System.out.println("Game Over");
					}
					booms.remove(i);
				}
				if(booms.get(i).isout()){
					booms.remove(i);
				}
				
			}
			
				
			for(int i = 0;i<herobooms.size();i++){
				
				herobooms.get(i).move();
				herobooms.get(i).draw(g);
				if(herobooms.get(i).hit(emenies)){
					
					Explore e = new Explore(herobooms.get(i).locx, herobooms.get(i).locy, 
							herobooms.get(i).imag.getHeight(null),herobooms.get(i).imag.getWidth(null));
					ex.add(e);
					
					score = score+100;
					
					herobooms.remove(i);
					
					if(hp.TP<100){
						hp.TP = hp.TP+15;
						if(hp.TP>100){
							hp.TP = 100;
						}
					}
					
				}else if(herobooms.get(i).hitboom(booms)){
					herobooms.remove(i);
					score =score +50;
				}else if(herobooms.get(i).isout()){
					herobooms.remove(i);
				}
			}
			
		try {
			Thread.sleep(50);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		}
		
		
	}
	
}
